
/**
 * 依赖 vue element-ui common.js
 * */
var MIXINS = {};

// 混入 - 公共
MIXINS.COMM = {
	data: function () {
		return {
			loadingCount: 0,
			loadingBox: null,
			loadingDefaultText: '加载中...',
			loadingText: '加载中...',
			refreshBadgeCode: '',
		}
	},
	methods: {
		// XML http request
		http: function (o) {
			var self = o.context || this;
			if (!o.noLoading) { self.loadingCount++ }
			request('', {
				url: ctx + o.url,
				type: o.type || 'get',
				data: o.data || {},
				async: o.notAsync != true,
				ContentType: o.ContentType || 'application/x-www-form-urlencoded;',
				timeout: o.timeout || '30000',
			}, function (res) {
				if (!o.noLoading) { self.loadingCount-- }
				typeof o.final == 'function' && o.final(res);
				if (res.success) {
					typeof o.success == 'function' && o.success(res);
				} else {
					if (typeof o.error == 'function') {
						return o.error(res);
					}
					self.$message.error(res.message || o.errorText || '获取数据失败');
				}
			}, function () {
				if (!o.noLoading) { self.loadingCount-- }
				typeof o.final == 'function' && o.final();
				if (typeof o.fail == 'function') {
					return o.fail();
				}
				self.$message.error('请求服务器失败，请检查链接有效性！');
			});
		},
		// 格式化时间
		fmtDate: function(time, formatStr){
			return UTIL.formatDate(time, formatStr);
		},
	},
	watch: {
		loadingCount: function (val) {
			var vm = this;
			if (val < 1) {
				if (this.loadingCount < 0) { this.loadingCount = 0; }
				window.setTimeout(function () {
					vm.loadingBox.close();
				}, 200);
				this.loadingText = this.loadingDefaultText;
			} else {
				this.loadingBox = this.$loading({
					lock: true,
					text: vm.loadingText,
					background: 'rgba(0, 0, 0, 0.7)'
				})
			}
		},
	},
};

// 混入 - 视图
MIXINS.VIEW = {};

// 混入 - 收件页
MIXINS.APPLY = {};